package com.msb.test01;

import java.sql.*;

public class Test2 {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        //1.加载驱动-----准备电话
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.获取数据库连接（connection）---输电话号
        String url="jdbc:mysql://192.168.151.33:3306/sxs?useSSL=false&useUnicode=true&characterEncoding=UTF8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
        String username="root";
        String password="123456";
        Connection conn = DriverManager.getConnection(url,username,password);
        //3.创建对话-SQL命令发送器（statement）--拨过去
        Statement sta = conn.createStatement();
        //4.通过statement发送SQL命令并得到结果 --谈话
        ResultSet rs = sta.executeQuery("select * from t_book");

        //5.处理结果
        while(rs.next()){
            System.out.println(rs.getInt("id")+"---"+rs.getString("name")+"---"+rs.getString("author")+"---"+rs.getDouble("price"));

        }
        //6.关闭数据库（Resultset，statement，connection）--挂电话
        sta.close();
        conn.close();

    }
}
